<?php
Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' );
Yii::app()->clientScript->registerCssFile(
	Yii::app()->clientScript->getCoreScriptUrl().
		'/jui/css/base/jquery-ui.css'
);
?>

<?php
$this->pageTitle=Yii::app()->name . ' - Добавление клиента';
$this->breadcrumbs=array(
	'Поиск'=>Yii::app()->createUrl('clients/search'),
	'Добавление клиента'
);
?>

<fieldset>
	<legend>Добавление клиента</legend>
	<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
		'id'=>'clients-form',
		'enableAjaxValidation'=>false,
	)); ?>

	<?php if($current_passport->getError('is_passport') or $prev_passport->getError('is_passport')):?>
		<div class="alert alert-error">
			<strong>Внимание!</strong> <?=$current_passport->getError('is_passport')?$current_passport->getError('is_passport'):$prev_passport->getError('is_passport')?>
		</div>
	<?php endif;?>

	<h4>Персональные данные</h4>
	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($model,'surname',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($model,'name',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($model,'patronymic',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
	</div>

	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($model,'dob',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($model,'birthplace',array('class'=>'input-block-level','maxlength'=>255)); ?>
		</div>
	</div>

	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($model,'phone',array('class'=>'input-block-level','maxlength'=>30)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($model,'email',array('class'=>'input-block-level','maxlength'=>100)); ?>
		</div>
	</div>

	<h4>Паспортные данные</h4>
	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($current_passport,'[1]series',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($current_passport,'[1]number',array('class'=>'input-block-level')); ?>
		</div>
	</div>

	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($current_passport,'[1]issued_date',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($current_passport,'[1]issued_by',array('class'=>'input-block-level','maxlength'=>255)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($current_passport,'[1]subdivision_code',array('class'=>'input-block-level','maxlength'=>7)); ?>
		</div>
	</div>

	<label class="checkbox text-success">
		<?=CHtml::checkBox('prev_passport_data',$model->prev_passport,array('id'=>'prev_passport_data'))?> Заполнить данные о ранее выданном паспорте
	</label>

	<div class="row" id="ppd-block">
		<div class="span4">
			<?php echo $form->textFieldRow($prev_passport,'[2]series',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($prev_passport,'[2]number',array('class'=>'input-block-level')); ?>
		</div>
	</div>

	<h4>Адрес прописки</h4>
	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($reg_address,'[1]post_index',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($reg_address,'[1]region',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($reg_address,'[1]city',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
	</div>

	<div class="row">
		<div class="span6">
			<?php echo $form->textFieldRow($reg_address,'[1]street',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span2">
			<?php echo $form->textFieldRow($reg_address,'[1]house',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span2">
			<?php echo $form->textFieldRow($reg_address,'[1]housing',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
		<div class="span2">
			<?php echo $form->textFieldRow($reg_address,'[1]apartment',array('class'=>'input-block-level','maxlength'=>250)); ?>
		</div>
	</div>

	<label class="checkbox text-success">
		<?=CHtml::checkBox('hab-address-check',false,array('id'=>'hab-address-check'))?> Заполнить адрес проживания, если не совпдает с адресом регистрации
	</label>

	<div id="hab-address-block" style="display: none;">
		<h4>Адрес проживания</h4>
		<div class="row">
			<div class="span4">
				<?php echo $form->textFieldRow($hab_address,'[2]post_index',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
			<div class="span4">
				<?php echo $form->textFieldRow($hab_address,'[2]region',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
			<div class="span4">
				<?php echo $form->textFieldRow($hab_address,'[2]city',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
		</div>

		<div class="row">
			<div class="span6">
				<?php echo $form->textFieldRow($hab_address,'[2]street',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
			<div class="span2">
				<?php echo $form->textFieldRow($hab_address,'[2]house',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
			<div class="span2">
				<?php echo $form->textFieldRow($hab_address,'[2]housing',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
			<div class="span2">
				<?php echo $form->textFieldRow($hab_address,'[2]apartment',array('class'=>'input-block-level','maxlength'=>250)); ?>
			</div>
		</div>
	</div>

	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'primary',
			'label'=>$model->isNewRecord ? 'Создать' : 'Применить',
		)); ?>

		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'link',
			'url'=>$model->isNewRecord ? Yii::app()->user->getReturnUrl() : Yii::app()->createUrl('clients/view',array('id'=>$model->id)),
			'type'=>'danger',
			'label'=>'Отмена',
		)); ?>
	</div>

	<?php $this->endWidget(); ?>
</fieldset>

<script type="text/javascript">
	$(document).ready(function(){
		jQuery(function($){
			$.datepicker.regional['ru'] = {
				closeText: 'Закрыть',
				prevText: '&#x3c;Пред',
				nextText: 'След&#x3e;',
				currentText: 'Сегодня',
				monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
					'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
				monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
					'Июл','Авг','Сен','Окт','Ноя','Дек'],
				dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
				dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
				dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
				weekHeader: 'Не',
				dateFormat: 'dd.mm.yy',
				firstDay: 1,
				isRTL: false,
				showMonthAfterYear: false,
				yearSuffix: ''};
			$.datepicker.setDefaults($.datepicker.regional['ru']);
		});

		$('#add-client-button').click(function() {
			$(this).button('loading'); // call the loading function
		});

		$( "#Clients_dob" ).datepicker({changeYear: true,yearRange: "-100:+0"});
		$( "#Passports_1_issued_date" ).datepicker({changeYear: true,yearRange: "-100:+0"});

		$('#prev_passport_data').click(function(){
			if($(this).is(':checked'))
				$('#ppd-block').slideDown();
			else
				$('#ppd-block').slideUp();
		});

		$('#hab-address-check').click(function(){
			if($(this).is(':checked'))
				$('#hab-address-block').slideDown();
			else
				$('#hab-address-block').slideUp();
		});

		if($('#prev_passport_data').is(':checked'))
			$('#ppd-block').show();
		else
			$('#ppd-block').hide();
	});
</script>